package top.wjgyy.tools.ddns;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

public class DDNSApplication extends Application {
    private static List<Consumer<Object>> closeActions = new ArrayList<>();

    public static void addCloseActions(Consumer<Object>... actions) {
        Collections.addAll(closeActions, actions);
    }

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader loader = new FXMLLoader(this.getClass().getResource("/view/index.fxml"));
        Parent load = (Parent) loader.load();
        stage.setScene(new Scene(load));
        stage.getIcons().add(new Image("/images/DNS.png"));
        stage.setTitle("DDNS");
        stage.initStyle(StageStyle.UNDECORATED);
        stage.show();
        stage.setOnHidden(event -> {
            for (Consumer<Object> closeAction : closeActions) {
                if (closeAction == null) continue;
                closeAction.accept(null);
            }
        });
    }

}
